package com.chinasoft.mall.activity;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;

import com.chinasoft.mall.R;
import com.chinasoft.mall.activity.adapter.ModelList2Adapter;
import com.chinasoft.mall.activity.subActivity.HomePageActivity;
import com.chinasoft.mall.activity.subActivity.more.HomePageMoreActivity;
import com.chinasoft.mall.framework.BeanCache;
import com.chinasoft.mall.framework.Config;
import com.chinasoft.mall.framework.ControllerCenter;
import com.chinasoft.mall.model.BaseBean;
import com.chinasoft.mall.model.response.ModelWeiboBean;
import com.chinasoft.mall.model.response.PushMessageBean;
import com.chinasoft.mall.widget.LoadListView;
import com.chinasoft.mall.widget.LoadListView.OnRefreshListener;

public class PushMessageActivity extends BaseActivity implements
		OnRefreshListener {

	private LoadListView modellist;
	private BaseBean modelweibo_bb;
	private ModelList2Adapter mlAdapter;
	private List<PushMessageBean> pmb = new ArrayList<PushMessageBean>();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sy_more_modellist2);
		initView();
	}

	@Override
	protected void onResume() {
		super.onResume();
		initRequest();
	}

	private void initRequest() {
//		modelweibo_bb = ControllerCenter.responsdata.get(Config.GET_MODELWEIBO);
//			if (modelweibo_bb != null) {
//				modelweibo_bb.reqData.put("pageNo", "1");
//				modelweibo_bb.reqData.put("pageSize", "10");
//				success(modelweibo_bb);
//			} else {
//				modelweibo_bb = new BaseBean(Config.GET_MODELWEIBO);
//				modelweibo_bb.reqData.put("pageNo", "1");
//				modelweibo_bb.reqData.put("pageSize", "10");
//				control.sendMessage(modelweibo_bb);
//			}
		modelweibo_bb = BeanCache.getInstance().getResponsdata().get(Config.PUSH_MESSAGE);
			if (modelweibo_bb != null) {
				modelweibo_bb.reqData.put("pageNo", "1");
				modelweibo_bb.reqData.put("pageSize", "10");
				success(modelweibo_bb);
			} else {
				modelweibo_bb = new BaseBean(Config.PUSH_MESSAGE);
				modelweibo_bb.reqData.put("pageNo", "1");
				modelweibo_bb.reqData.put("pageSize", "10");
				control.sendMessage(modelweibo_bb);
			}
	}

	private void initView() {
		modellist = (LoadListView) findViewById(R.id.modellist);
		mlAdapter = new ModelList2Adapter((MainActivity) this.getParent(), null);
		modellist.setAdapter(mlAdapter);
		modellist.setonRefreshListener(this);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void success(BaseBean obj) {
		super.success(obj);
		if (obj.equals(modelweibo_bb)) {

//				if (obj.getResData() != null
//						&& obj.getResData().getData() != null) {
//					mwbs.addAll((List<ModelWeiboBean>) obj.getResData()
//							.getData());
//					mlAdapter.setData(mwbs);
//					modellist.onRefreshComplete();
//				}
				if (obj.getResData() != null
						&& obj.getResData().getData() != null) {
					pmb.addAll((List<PushMessageBean>) obj.getResData()
							.getData());
					mlAdapter.setData(pmb);
					modellist.onRefreshComplete();
				}
			}
		}
	

	@Override
	public void onRefresh() {
		modelweibo_bb.reqData.put("pageNo",
				(Integer.parseInt(modelweibo_bb.reqData.get("pageNo")) + 1)
						+ "");
		control.postMessage(modelweibo_bb);
	}
}
